package com.gc.services.impl;

import com.gc.dao.custom.MhyMediaMapper;
import com.gc.dao.custom.MhyProcessDataInfoMapper;
import com.gc.dao.custom.MhyProcessNoInfoMapper;
import com.gc.dao.custom.MhySmokeDetectionInfoMapper;
import com.gc.dto.VehicleImageDTO;
import com.gc.dto.VehicleResultImageDTO;
import com.gc.pojo.SysMhyMedia;
import com.gc.pojo.SysMhyProcessDataInfo;
import com.gc.pojo.SysMhyProcessNoInfo;
import com.gc.pojo.SysMhySmokeDetectionInfo;
import com.gc.services.MhyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MhyServiceImpl implements MhyService {
    @Autowired
    private MhyProcessNoInfoMapper mhyProcessNoInfoMapper;
    @Autowired
    private MhyProcessDataInfoMapper mhyProcessDataInfoMapper;
    @Autowired
    private MhySmokeDetectionInfoMapper mhySmokeDetectionInfoMapper;
    @Autowired
    private MhyMediaMapper mhyMediaMapper;

    @Override
    public int addProcessNoInfo(SysMhyProcessNoInfo processNoInfo) {
        return mhyProcessNoInfoMapper.insert(processNoInfo);
    }

    @Override
    public int addProcessDataInfoList(List<SysMhyProcessDataInfo> processDataInfos) {
        return mhyProcessDataInfoMapper.insertList(processDataInfos);
    }

    @Override
    public SysMhySmokeDetectionInfo selectMhySmokeDetectionInfoByUUId(String uuid) {
        return mhySmokeDetectionInfoMapper.selectByUUId(uuid);
    }

    @Override
    public int addMhySmokeDetectionInfo(SysMhySmokeDetectionInfo smokeDetectionInfo) {
        return mhySmokeDetectionInfoMapper.insert(smokeDetectionInfo);
    }

    @Override
    public int modifyMhySmokeDetectionInfoById(SysMhySmokeDetectionInfo smokeDetectionInfo) {
        return mhySmokeDetectionInfoMapper.updateByPrimaryKey(smokeDetectionInfo);
    }

    @Override
    public SysMhyMedia getMhyMediaByProcessNo(String processNo) {
        return mhyMediaMapper.selectByProcessNo(processNo);
    }

    @Override
    public int modifyMhyMediaById(SysMhyMedia mMM) {
        return mhyMediaMapper.updateByPrimaryKeySelective(mMM);
    }

    @Override
    public SysMhyMedia getMhyMediaByUUId(String uuid) {
        return mhyMediaMapper.selectByUUId(uuid);
    }

    @Override
    public int addMhyMedia(VehicleImageDTO vi) {
        SysMhyMedia mm = new SysMhyMedia();
        mm.setUuid(vi.getUuid());
        if(encapsulation(vi,mm) == 0){
            return 0;
        }
        return mhyMediaMapper.insert(mm);
    }

    @Override
    public int modifyMhyMedia(VehicleImageDTO vi, Integer mediaId) {
        SysMhyMedia mm = new SysMhyMedia();
        mm.setMediaId(mediaId);
        if(encapsulation(vi,mm) == 0){
            return 0;
        }
        return mhyMediaMapper.updateByPrimaryKeySelective(mm);
    }


    private int encapsulation(VehicleImageDTO vi,SysMhyMedia mm){
        switch (vi.getFilename()) {
            case "F_PIC1":
                mm.setfPic1(vi.getFileData());
                break;
            case "F_PIC2":
                mm.setfPic2(vi.getFileData());
                break;
            case "F_PIC3":
                mm.setfPic3(vi.getFileData());
                break;
            case "F_PIC4":
                mm.setfPic4(vi.getFileData());
                break;
            case "F_PIC5":
                mm.setfPic5(vi.getFileData());
                break;
            case "F_PIC6":
                mm.setfPic6(vi.getFileData());
                break;
            case "F_PIC7":
                mm.setfPic7(vi.getFileData());
                break;
            case "F_PIC8":
                mm.setfPic8(vi.getFileData());
                break;
            case "F_PIC9":
                mm.setfPic9(vi.getFileData());
                break;
            case "F_FRZSYYZZ":
                mm.setfFrzsyyzz(vi.getFileData());
                break;
            case "F_ET_PIC1":
                mm.setfEtPic1(vi.getFileData());
                break;
            case "F_ET_PIC2":
                mm.setfEtPic2(vi.getFileData());
                break;
            case "F_ET_PIC3":
                mm.setfEtPic3(vi.getFileData());
                break;
            default:
                return 0;
        }
        return 1;
    }
    private int encapsulation2(VehicleResultImageDTO vri, SysMhyMedia mm){
        switch (vri.getFilename()) {
            case "F_ET_PIC1":
                mm.setfEtPic1(vri.getFileData());
                break;
            case "F_ET_PIC2":
                mm.setfEtPic2(vri.getFileData());
                break;
            case "F_ET_PIC3":
                mm.setfEtPic3(vri.getFileData());
                break;
            default:
                return 0;
        }
        return 1;
    }

}
